//
//  TTUserModel.m
//  ExhibitionHall
//
//  Created by 王洋 on 2019/6/15.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "TTUserModel.h"

extern NSString * const kUserNickNameCache; //用户名缓存
extern NSString * const kUserIconPathCache; //用户名缓存
extern NSString * const kLoginTokenCache; //用户名缓存

@interface TTUserModel ()

@property (nonatomic, strong) NSUserDefaults *userModelDefault;

@end

@implementation TTUserModel

+ (TTUserModel *)sharedObject {
    static TTUserModel *shareInstance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        
        shareInstance = [TTUserModel new];
    });
    return shareInstance;
}

- (void)initialization {
    
    self.userName = @"";
    self.userIconURL = @"";
    self.accessToken = @"";
    
    [self.userModelDefault setValue:@"" forKey:@"access_token"];
    [self.userModelDefault setValue:@"" forKey:@"uer_name"];
    [self.userModelDefault setValue:@"" forKey:@"user_icon"];
    [self.userModelDefault synchronize];

}


- (NSString *)accessToken {
    
    NSString *access_token =[self.userModelDefault valueForKey:@"access_token"];
    if (!access_token.length) {
        access_token = @"Basic Zm9vOmJhcg==";
    }
    return access_token;
}

- (NSString *)userName {
    
    NSString *user_name = [self.userModelDefault valueForKey:@"uer_name"];
    if (!user_name.length) {
        user_name = @"未获取到用户名";
    }
    return user_name;
}

-(NSString *)userIconURL {
    
    NSString *user_icon = [_userModelDefault valueForKey:@"user_icon"];
    if (!user_icon.length) {
        user_icon = @"http://e.hiphotos.baidu.com/bainuo/wh=720,436/sign=6e905b9028738bd4c474ba3693bbabe2/b812c8fcc3cec3fd48278338d088d43f87942765.jpg";
    }
    return user_icon;
}

-(NSUserDefaults *)userModelDefault {
    if (!_userModelDefault) {
        _userModelDefault = [NSUserDefaults standardUserDefaults];
    }
    return _userModelDefault;
}

@end
